import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;


public class weatherForecast {

    //parm：请求的url链接  返回的是json字符串
	public static String getURLContent(final String urlStr) {
		URL url = null;
		BufferedReader in = null;
		final StringBuffer sb = new StringBuffer();
		try {
			url = new URL(urlStr);
			in = new BufferedReader(new InputStreamReader(url.openStream(), "UTF-8"));
			String str = null;
			// ?????н??ж???
			while ((str = in.readLine()) != null) {
				sb.append(str);
			}
		} catch (final Exception ex) {
		} finally {
			try {
				if (in != null) {
					in.close(); // ?????
				}
			} catch (final IOException ex) {
			}
		}
		final String result = sb.toString();
		return result;
	}

	public static String showWeatherNow(final String location, final String key) {
		final String baseUrl = "https://free-api.heweather.com/s6/weather/now?location=" + location + "&key=" + key;
		final String weather_txt = getURLContent(baseUrl);
		final JSONObject weatherJson = new JSONObject(weather_txt);
		// weather informations
		// update time
		final String update_time = weatherJson.getJSONArray("HeWeather6").getJSONObject(0).getJSONObject("update")
				.getString("loc");

		return update_time;
	}

public static void main(final String []args) {
		
	String location = "auto_ip";
	String key      = "322389fe745246a88c9371a867475438";
	// now Air quality
	//String air_qlty_now = "https://free-api.heweather.com/s6/air/now?location=" + location + "&key=" + key;
    
	System.out.println(showWeatherNow(location, key)); 
		
}
}